package com.dingwen.treasure.business.component;

import com.dingwen.treasure.base.constant.PayConstant;
import com.dingwen.treasure.business.feign.TreasureTaskFeignClient;
import com.dingwen.treasure.business.service.PayService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 　AsyncComponent
 *  <pre>
 *      1. @Async() 不指定线程池时使用的时使用默认的，需要指定自定义的线程池需要指定线程池的BeanId。注意需要使用@Async功能必须通过@EnableAsync开启
 *      2. @Async("asyncExecutor") 作用在类上表示该类下所有方法都采用该策略处理
 * </pre>
 * 　@author dingwen
 * 　@date 2022/5/13
 */
@Async("asyncExecutor")
@Component
@Slf4j
@RequiredArgsConstructor
public class AsyncComponent {

    /**
     * payService
     */
    @Resource(name = PayConstant.WX_PAY)
    private PayService payService;

    /**
     *
     */
    private final TreasureTaskFeignClient treasureTaskFeignClient;

    /**
     * 测试异步任务1
     */
    public void taskOne() {
        log.info("当前执行任务线程：{}", Thread.currentThread().getName());
        treasureTaskFeignClient.test(1L);
    }

    /**
     * 测试异步任务2: {@link PayConstant##WX_PAY}
     */
    public void taskTwo() {
        log.info("当前执行任务线程：{}", Thread.currentThread().getName());
        payService.pay();
    }
}
